from pymysql import connect,cursors

USERNAME ='root'
PASSWORD = 'jisuanji2022'
HOST = '121.196.166.117'
PORT = 3306
DATABASE = 'woniunote'

def query_data(sql_str):
    try:
        conn = connect(host=HOST, port=PORT, database=DATABASE, user=USERNAME, password=PASSWORD)

        cur = conn.cursor(cursors.DictCursor)

        row_count = cur.execute(sql_str)

        conn.commit()

        result = cur.fetchall()

    except Exception as e:
        print(e)

    finally:
        cur.close()
        conn.close()
        return result